import type {
  OrderCreateParams,
  OrderCreateResult,
  OrderListParams,
  OrderListResult,
  OrderLogisticResult,
  OrderPreResult,
  OrderResult,
} from '@/types/order'
import { http } from '@/utils/http'

// 获取用户预付订单
export const getMemberOrderPre = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET',
  })
}

// 获取立即购买订单
export const getMemberOrderPreNow = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data,
  })
}

// 提交订单
export const postMemberOrder = (data: OrderCreateParams) => {
  return http<OrderCreateResult>({
    url: '/member/order',
    method: 'POST',
    data,
  })
}

// 获取订单详情信息
export const getMemberOrderDetail = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}`,
    method: 'GET',
  })
}

// 获取再次购买订单
export const getMemberOrderRepurchase = (id: string) => {
  return http<OrderPreResult>({
    url: `/member/order/repurchase/${id}`,
    method: 'GET',
  })
}

// 模拟发货接口
export const getMemberOrderConsignment = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET',
  })
}

// 确认收货
export const putMemberOrderReceipt = (id: string) => {
  return http({
    url: `/member/order/${id}/receipt`,
    method: 'PUT',
  })
}

// 获取订单物流
export const getOrderTransform = (id: string) => {
  return http<OrderLogisticResult>({
    url: `/member/order/${id}/logistics`,
    method: 'GET',
  })
}

// 删除订单
export const deleteOrder = (ids: string[]) => {
  return http<OrderLogisticResult>({
    url: `/member/order`,
    method: 'GET',
    data: { ids },
  })
}

// 获取订单列表
export const getOrderList = (data: OrderListParams) => {
  return http<OrderListResult>({
    url: '/member/order',
    method: 'GET',
    data,
  })
}
